package leetcode.code1436;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import leetcode.helper.HelpDebug;

public class Solution1436 {

	public String destCity(List<List<String>> paths) {
		Set<String> from = new HashSet<>();
		for (List<String> path : paths) {
			from.add(path.get(0));
		}
		for (List<String> path : paths) {
			if(!from.contains(path.get(1))) {
				return path.get(1);
			}
		}
		return null;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str = "[[\"London\",\"New York\"],[\"New York\",\"Lima\"],[\"Lima\",\"Sao Paulo\"]]";
		String e = "\"Sao Paulo\"";
		Solution1436 so = new Solution1436();
		String r = so.destCity(HelpDebug.str2intlist2(str));
		HelpDebug.compare(e, r);

		str = "[[\"pYyNGfBYbm\",\"wxAscRuzOl\"],[\"kzwEQHfwce\",\"pYyNGfBYbm\"]]";
		e = "\"wxAscRuzOl\"";
		r = so.destCity(HelpDebug.str2intlist2(str));
		HelpDebug.compare(e, r);

	}

}
